﻿/********************************************************************************
** @ Date:2024/09/11
** @ Author: WeiXiaoYu
** @ Description: 输出pdf报表基类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef COptPdfRptBase_H
#define COptPdfRptBase_H
#include <QObject>
#include <QVector>
#include <QDateTime>
#include <QMap>
#include <QPrinter>
#include <QPainter>
#include "cimagedownloader.h"

//Pdf输出的巡检项类型定义
enum EmPdfOutItemTypeDef
{
	EN_None,//无

	EN_PM25,//PM2.5
	EN_PM10,//PM10
	EN_Co,//一氧化碳
	EN_CombustibleGas,//可燃气体
	EN_Temperature,//温度
	EN_Humidity,//湿度

	EN_InfraredThermometry,//红外测温
	EN_BeltOffTrack,//皮带跑偏(用不到)
	EN_PhotoGraph,//图像相机
	EN_Voice//声音
};

//其他AI检测算法类型
enum EPdfExteraAiType
{
	enConvBeltForeObjDet = 0,//传送带异物识别
	enConvBeltMassFlowDet,//传送带煤流量检测

	enUnknowAriType //未知算法类型
};

//Pdf输出的巡检项信息
class CPdfOutInspecItemInfoAll
{
public:
	EmPdfOutItemTypeDef emPdfOutItemType;//巡检项类型

	double m_doMeasurementVal;//测量数值
	QString m_strState;//状态(正常/超上限)
	QString m_strRemark;//例如:上限32mg  其中\n代表换行 (改成显示阈值了-->上限:45℃)
	QString m_strUnit;//单位
	bool m_bStateOk;//是否正常(用于判断显示字体颜色)
	bool m_bIsAction;//是否执行
	QString m_sItemName;//新增巡检项名称(云台巡检项展示巡检项名称,本体也要)

	QString m_strPictureAddress;//图片地址(云台巡检项才有)
	QString m_sHttpPicAddr;//http图片地址(图像相机(新的AI巡检项) 是用的这个http地址)
	QString m_strPictureRemark;//图片备注

	CPdfOutInspecItemInfoAll()
	{
		emPdfOutItemType = EmPdfOutItemTypeDef::EN_None;

		m_doMeasurementVal = 0;
		m_strState = "";
		m_strRemark = "";
		m_strPictureAddress = "";
		m_strUnit = "";
		m_bStateOk = true;//默认正常
		m_strPictureRemark = "";
		m_bIsAction = false;
		m_sItemName = "";

	}
};

//表格中包含的巡检点信息
class CFormInspectionPointInfo
{
public:
	double m_douPointSortIndex;//排序号(不显示在表格里,用于给巡检点排序的)

	QString m_strInspectionPointName;//巡检点名称
	QString m_strRobotName;//机器人名称
	QString m_strLocation;//位置
	int m_nRollerCode;//托辊号(默认是0,是0就不显示在位置后面了)
	QString m_sRollerDesc;//托辊描述
	double  m_dLocation;//位置用于排序
	QString m_strInspectDate;//巡检日期 2023-11-13
	QString m_strInspectTime;//巡检时间 09:04:00
	QString m_strRemark;//备注(暂时为空，预留)

	QVector<CPdfOutInspecItemInfoAll> m_vecInspecItemsInfo;//巡检项信息(每个巡检点 可能勾选不同个数的巡检项 个数是不确定的)

	CFormInspectionPointInfo()
	{
		m_douPointSortIndex = 0;//排序号(不显示在表格里,用于给巡检点排序的)

		m_strInspectionPointName = "";//巡检点名称
		m_strRobotName = "";//机器人名称
		m_strLocation = "";//位置
		m_nRollerCode = 0;//托辊号(默认是0,是0就不显示在位置后面了)
		m_sRollerDesc = "";//托辊描述(上面的int型废弃了)
		m_strInspectDate = "";//巡检日期
		m_strInspectTime = "";//巡检时间
		m_strRemark = "";//备注
	}
};



//连续声音信息
class CPdfCotVoiceInfo
{
public:
	QString m_strAlmDesc;//报警描述
	double m_dLocation;//位置(m)
	int m_nRollerCode;//托辊号
	QString m_sRollerDesc;//托辊描述(上面的int托辊号废除)
	double m_dValue;//噪声值
	QString m_sRemark;//备注
	int m_nAlmState;//报警状态 0:正常 1:高报 2:高高报 -1:低报 -2:低低报
	QDateTime m_dtActionTime;//add执行时间

	//后面计算赋值的数据
	int nBelongTier;//归属层级 0:去程 1:归程

	CPdfCotVoiceInfo()
	{
		m_strAlmDesc = "";
		m_dLocation = 0;
		m_nRollerCode = 0;//托辊号
		m_sRollerDesc = "";//托辊描述(上面的int托辊号废除)
		m_dValue = 80;
		m_sRemark = "";
		m_nAlmState = 0;

		//后面计算赋值的数据
		nBelongTier = 0;
	}
};

//连续红外信息
class CPdfCotIrInfo
{
public:
	QString m_strAlmDesc;//报警描述 超上限等
	double m_dLocation;//位置(m)
	int m_nRollerCode;//托辊号
	QString m_sRollerDesc;//托辊描述(上面的int废弃)
	QString m_sRemark;//备注(改成阈值填写 高限50℃)
	double m_doMeasurementVal;//测量数值
	QString m_sPictureAddress;//图片地址
	QString m_sPictureRemark;//图片备注
	int m_nAlmState;//报警状态 0:正常 1:高报 2:高高报 -1:低报 -2:低低报
	QDateTime m_dtActionTime;//add执行时间

	//后面计算赋值的数据
	int nBelongTier;//归属层级 0:去程 1:归程

	CPdfCotIrInfo()
	{
		m_strAlmDesc = "";
		m_dLocation = 0;
		m_nRollerCode = 0;
		m_sRollerDesc = "";
		m_sRemark = "";
		m_doMeasurementVal = 0;
		m_sPictureAddress = "";
		m_sPictureRemark = "";
		m_nAlmState = 0;

		//后面计算赋值的数据
		nBelongTier = 0;
	}
};

//连续图像信息
class CPdfCotImageInfo
{
public:
	//QString m_strAlmDesc;//报警描述 超上限等
	double m_dLocation;//位置(m)
	int m_nRollerCode;//托辊号
	QString m_sRollerDesc;//托辊描述
	//QString m_sRemark;//备注(改成阈值填写 高限50℃)
	//double m_doMeasurementVal;//测量数值
	//QString m_sPictureAddress;//图片地址
	QString m_sHttpPicAddr;//http图片地址
	QString m_sPictureRemark;//图片备注
	int m_nAlmState;//报警状态 0:正常 1:高报 2:高高报 -1:低报 -2:低低报
	QDateTime m_dtActionTime;//add执行时间

	//后面计算赋值的数据
	int nBelongTier;//归属层级 0:去程 1:归程

	CPdfCotImageInfo()
	{
		//m_strAlmDesc = "";
		m_dLocation = 0;
		m_nRollerCode = 0;
		m_sRollerDesc = "";
		//m_sRemark = "";
		//m_doMeasurementVal = 0;
		//m_sPictureAddress = "";
		m_sHttpPicAddr = "";
		m_sPictureRemark = "";
		m_nAlmState = 0;

		//后面计算赋值的数据
		nBelongTier = 0;
	}
};


//PDF输出的报表信息(机器人巡检任务信息)
class CPdfReportInfo
{
public:
	QString m_strTaskActionId;//子任务Id(用于更新数据库中的pdf存储地址)
	QString m_strOutputPdfFolder;//输出pdf文件夹

	QString m_trClientCompanyNameTemp;//客户电厂名称
	QString m_strRobotName;//机器人名称
	QString m_strTaskName;//巡检任务名称
	QString m_strTaskTime;//巡检日期 2023-11-10
	QString m_strComment;//备注
	QString m_strTaskStartTime;//任务开始时间
	QString m_strTaskEndTime;//任务结束时间
	QString m_strTaskStartElectricalValue;//任务开始电量
	QString m_strTaskEndElectricalValue;//任务结束电量
	QString m_strTaskState;//任务状态
	QString m_strPercentOfPass;//合格率
	QString m_strInspectionPointCount;//巡检点数量
	QString m_strInspectionItemCount;//巡检项数量
	QString m_strInspectionItemNormalCount;//巡检项正常数量
	QString m_strInspectionItemAbnormalCount;//巡检项异常数量(拼接好的显示用的字符串)
	int m_nInspectionItemAbnormalCount;//巡检项异常数量(实际个数,用于判断是否红色加粗显示)
	QVector<QString> m_vecAbnormalBriefList;//异常项简要信息列表,有几项，增加几行

	QVector<CFormInspectionPointInfo> m_vecFormInspectionPointInfo;//表格所有巡检点信息Vec容器

	//连续检测结果
	QVector<CPdfCotVoiceInfo> m_VecCotVoiceInfo;//连续声音结果数组
	QVector<CPdfCotIrInfo> m_VecCotIrInfo;//连续红外结果数组
	QVector<CPdfCotImageInfo> m_VecCotImageInfo;//连续图像结果数组

	CPdfReportInfo()
	{
		m_strTaskActionId = "hehehe";
		m_strOutputPdfFolder = "D:\\Test\\Report";//默认这个

		m_trClientCompanyNameTemp = "";//客户电厂名称
		m_strRobotName = "";//机器人名称
		m_strTaskName = "";//巡检任务名称
		m_strTaskTime = "";//巡检日期 2023-11-10
		m_strComment = "";//备注
		m_strTaskStartTime = "";//任务开始时间
		m_strTaskEndTime = "";//任务结束时间
		m_strTaskStartElectricalValue = "";//任务开始电量
		m_strTaskEndElectricalValue = "";//任务结束电量
		m_strTaskState = "";//任务状态
		m_strPercentOfPass = "";//合格率
		m_strInspectionPointCount = "";//巡检点数量
		m_strInspectionItemCount = "";//巡检项数量
		m_strInspectionItemNormalCount = "";//巡检项正常数量
		m_strInspectionItemAbnormalCount = "";//巡检项异常数量
		m_nInspectionItemAbnormalCount = 0;//巡检项异常数量(实际个数,用于判断是否红色加粗显示)
	}
};
//纠偏单个报警信息
class CPdfRecSglAlmInfo
{
public:
	QString m_sPictureUrl;//图片URL地址(现在改成了http图片地址)
	QString m_sBeltName;//皮带名称
	QString m_sRecPointName;//纠偏点名称
	QString m_sRecStartTime;//跑偏开始时间
	QString m_sRecEndTime;//跑偏结束时间

	CPdfRecSglAlmInfo()
	{
		m_sPictureUrl = "";
		m_sBeltName = "";
		m_sRecPointName = "";
		m_sRecStartTime = "";
		m_sRecEndTime = "";
	}
};

//纠偏信息
class CPdfRectifyInfo
{
public:
	QString m_strBeltName;//皮带名称
	QString m_strDetTime;//检测日期 2024-05-13
	QString m_strDetStartTime;//检测开始时间 15:27:20
	QString m_strDetEndTime;//检测结束时间 16:30:45
	int m_nAlmCount;//报警项数
	QString m_strComment;//备注

	QVector<CPdfRecSglAlmInfo> m_vecFormRecAlmInfo;//纠偏报警信息容器

	CPdfRectifyInfo()
	{
		m_strBeltName = "";
		m_strDetTime = "";
		m_strDetStartTime = "";
		m_strDetEndTime = "";
		m_nAlmCount = 0;
		m_strComment = "";


	}
};

//撕裂单个报警信息
class CPdfTearSglAlmInfo
{
public:
	QString m_sPictureUrl;//图片URL地址(现在改成了http图片地址)
	QString m_sBeltName;//皮带名称
	QString m_sTearPointName;//撕裂点名称
	QString m_sTearStartTime;//撕裂开始时间
	QString m_sTearEndTime;//撕裂结束时间

	CPdfTearSglAlmInfo()
	{
		m_sPictureUrl = "";
		m_sBeltName = "";
		m_sTearPointName = "";
		m_sTearStartTime = "";
		m_sTearEndTime = "";
	}
};


//Ai图片框选区域
class CPdfAiPicPolygonArea
{
public:
	bool bPolygonAlarm;          //框选区域是否报警
	double dPolygonScore;        //框选区域得分
	QPoint pPoint;               //报警区域坐标
	double dWidth;               //宽度
	double dHeight;              //高度

	CPdfAiPicPolygonArea()
	{
		bPolygonAlarm = false;
		dPolygonScore = 0;
		dWidth = 0;
		dHeight = 0;
	}
};
//其他AI检测单个报警信息
class CPdfExtraAiAlmInfo
{
public:
	QString m_sAlmTime;//报警时间
	QString m_sAlmDesc;//报警描述
	QString m_sHttpPictureUrl;//Http图片地址
	QVector<CPdfAiPicPolygonArea> vecPolygonArea;  //图片框选区域
	double m_dImageWid;//图片宽度
	double m_dImageHig;//图片高度

	CPdfExtraAiAlmInfo()
	{
		m_sAlmTime = "";
		m_sAlmDesc = "";
		m_sHttpPictureUrl = "";
		m_dImageWid = 1920;
		m_dImageHig = 1080;
	}
};


//撕裂信息
class CPdfTearInfo
{
public:
	QString m_strBeltName;//皮带名称
	QString m_strDetTime;//检测日期 2024-05-13
	QString m_strDetStartTime;//检测开始时间 15:27:20
	QString m_strDetEndTime;//检测结束时间 16:30:45

	int m_nAlmCount;//报警项数
	QString m_strComment;//备注

	QVector<CPdfTearSglAlmInfo> m_vecFormTearAlmInfo;//撕裂报警信息容器

	CPdfTearInfo()
	{
		m_strBeltName = "";
		m_strDetTime = "";
		m_strDetStartTime = "";
		m_strDetEndTime = "";

		m_nAlmCount = 0;
		m_strComment = "";


	}
};

//其他AI检测信息
class CPdfExtraAiInfo
{
public:
	QString m_strBeltName;//皮带名称
	QString m_strDetTime;//检测日期 2024-05-13
	int m_nAlmCount;//报警项数
	QString m_strComment;//备注
	QString m_strDetStartTime;//检测开始时间 15:27:20
	QString m_strDetEndTime;//检测结束时间 16:30:45
	QMap<int, QVector<CPdfExtraAiAlmInfo>> m_mapExtraAiInfo;//其他AI检测报警map int:类型(0:传送带异物识别 1:传送带煤流量检测)

	CPdfExtraAiInfo()
	{
		m_strBeltName = "";
		m_strDetTime = "";
		m_nAlmCount = 0;
		m_strComment = "";
		m_strDetStartTime = "";
		m_strDetEndTime = "";
	}
};

class CTaskExecInfo;
class CDevDataBase;
class COptPdfRptBase  : public QObject
{
	Q_OBJECT

public:
	COptPdfRptBase(QObject *parent);
	virtual ~COptPdfRptBase() = default;

public:
	// 纯虚函数，没有实现，子类需要实现
	virtual bool optRobPdfRptInfo(CPdfReportInfo CRobData, QString &sErrMsg) = 0;//输出pdf报表信息(机器人巡检任务)
	virtual bool pkgExpRobReport(CTaskExecInfo* pTaskExecInfo, CDevDataBase* pDevData, QString strComment, QString &sErrMsg) = 0;//组包导出机器人报表
	virtual bool optSynthPdfRptInfo(CPdfReportInfo CRobData, CPdfRectifyInfo &CRectifyData, CPdfTearInfo &CTearData, CPdfExtraAiInfo &CExtraAiInfo, QString &sErrMsg) = 0;//输出pdf报表信息(机器人巡检任务、纠偏、撕裂、其他AI检测)
	virtual bool pkgExpSynthReport(CTaskExecInfo* pTaskExecInfo, CDevDataBase* pDevData, QString strComment, CPdfRectifyInfo &CRectifyData, CPdfTearInfo &CTearData, CPdfExtraAiInfo &CExtraAiInfo, QString &sErrMsg) = 0;//组包导出综合报表(机器人巡检任务、纠偏、撕裂、其他AI检测)
	virtual void drawNewPageCotAll(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIrInfo, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage, QPainter &painter, QPrinter &printer) = 0;//绘制所有的连续检测数据
	virtual void drawGroupCot(int nDrawType, int &nRowTemporary, QVector<CPdfCotIrInfo> vecDataIr, QVector<CPdfCotVoiceInfo> vecDataVoice, QVector<CPdfCotImageInfo> vecDataImage, QPainter &painter) = 0;//画一组连续检测

	virtual bool optRectifyPdfRptInfo(CPdfReportInfo CRobData, CPdfRectifyInfo &CRectifyData, QString &sErrMsg) = 0;//输出纠偏报表信息
	virtual bool pkgRectifyReport(CPdfRectifyInfo &CRectifyData, QString &sErrMsg) = 0;//组包导出纠偏报表
	virtual bool pkgRectifyReport(CPdfRectifyInfo &CRectifyData, QString &sErrMsg, QString &sPdfPath) = 0;//组包导出纠偏报表
	virtual bool optTearPdfRptInfo(CPdfReportInfo CRobData, CPdfTearInfo &CTearData, QString &sErrMsg) = 0;//输出撕裂报表信息
	virtual bool pkgTearReport(CPdfTearInfo &CTearData, QString &sErrMsg) = 0;//组包导出撕裂报表
	virtual bool optRestAiPdfRptInfo(CPdfReportInfo CRobData, CPdfExtraAiInfo &CExtraAiInfo, QString &sErrMsg) = 0;//输出其他AI检测报表信息
	virtual bool pkgRestAiReport(CPdfExtraAiInfo &CExtraAiInfo, QString &sErrMsg) = 0;//组包导出其他AI检测报表

protected:
	void getBetwTwoRollerCotData(int nStartRoller, int nEndRoller, QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QVector<CPdfCotIrInfo> &vecAllCotIr, QVector<CPdfCotVoiceInfo> &vecAllCotVoice);//获取两点托辊号之间的 连续红外检测数据、连续噪声检测数据
	void getCotMapIrData(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QVector<CPdfCotIrInfo> &vecAllCotIr);//获取连续检测红外Map数据
	void getCotMapVoiceData(QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QVector<CPdfCotVoiceInfo> &vecAllCotVoice);//获取连续检测声音Map数据
	void getCotMapImageData(QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage, QVector<CPdfCotImageInfo> &vecAllCotImage);//获取连续检测图像Map数据
	void calculateCotRetBelongTier(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIr, QMap<int, QVector<CPdfCotVoiceInfo>> &mapCotVoice, QMap<int, QVector<CPdfCotImageInfo>> &mapCotImage);//计算连续检测结果归属层级
	void drawNewPageCotIr(QMap<int, QVector<CPdfCotIrInfo>> &mapCotIrInfo, QPainter &painter, QPrinter &printer);//绘制新的一个连续红外

protected:
	void drawRowFormMergeL1R3(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QString sLeftInfo, QString sRightInfo, QPainter &painter);//画一行表格合并左1右3
	void drawRowFormCol4(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QVector<QString> vecInfo, QPainter &painter);//画一行表格4列
	void drawRowFormCol4(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, QVector<QString> vecInfo, QPainter &painter, QVector<bool> vecAbnormal);//画一行表格4列(带vecAbnormal判断字体颜色)
	void drawMergeMultiRowOneCol(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, int nMergeRowNum, QString sDataInfo, QPainter &painter, bool bAbnormal = false);//绘制合并多行1列
	void drawMergeMultiColOneRow(int nCellStartX, int nCellStartY, int nCellWidth, int nCellHeight, int nMergeColNum, QString sDataInfo, QPainter &painter, bool bAbnormal = false);//绘制合并多列1行
	
};
#endif
